<?php
	include "../init.php";
	$result=array();
	// print_r($_POST);
	foreach ($_POST['banner'] as $key => $value) {
		$result[$key]['banner']=$value;
	}
	foreach ($_POST['title'] as $key => $value) {
		$result[$key]['title']=$value;
	}
	foreach ($_POST['link'] as $key => $value) {
		$result[$key]['link']=$value;
	}
	
	$jsbanner=json_encode($result);
	//查询之前是否存在banner字段
	$data=array('settingkey'=>'banner','settingvalue'=>$jsbanner);
	$sql = "SELECT id FROM setting WHERE settingkey='banner';";
	$r = $mysql->getOne($sql);
	echo $r;
	if ($r) {//存在则进行更新
		// $sql="UPDATE setting SET settingvalue='{$jsbanner}' WHERE settingkey='banner';";
		$sql= "DELETE FROM setting WHERE settingkey='banner' ";
		$mysql->query($sql);
		$mysql->addRow('setting',$data);
	}else{//不存在进行添加banner
		//增加首页图片字段
		$mysql->addRow('setting',$data);
	}
	
	echo json_encode(array('code'=>'000','msg'=>'保存成功'));
	